/*
 * @Description: 
 * @Version: 2.0
 * @Autor: wangmiao
 * @Date: 2022-11-07 09:52:03
 * @LastEditors: wangmiao
 * @LastEditTime: 2022-11-07 11:16:07
 */

const path = require('path')
const HtmlPlugin = require('html-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin');

module.exports = {
  mode: 'development',
  entry: {
    index: path.resolve(__dirname, './src/index.js'),
    index2: path.resolve(__dirname, './src/index2.js')
  },
  output: {
    path: path.join(__dirname, 'dist'),
    filename: '[name].[hash].js',
  },
  plugins: [
    new HtmlPlugin({
      template: './src/index.html',
      filename: './index.html'
    }),
    new CleanWebpackPlugin()
  ],

  // 优化
  optimization: {
    splitChunks: {
      chunks: 'all',  // async: 异步的才分包  all： 全部做分包处理
      minSize: 0
    }
  },
  
  devServer: {
    // 首次打包成功后，自动打开浏览器
    open: true,
    // 在 http 协议中，如果端口号是 80，则可以被省略
    port: 80,
    // 指定运行的主机地址
    host: 'localhost'
  },
}